<?php

namespace console\controllers;

use Yii;
use yii\helpers\Console;

/**
 * Manages application migrations.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class TestController extends \yii\console\Controller {

    /**
     * @view update.php
     * @return mixed
     */
    public function actionIndex() {
        Yii::error([
            'name' => 'TestController',
            'action' => 'actionIndex',
            date('Y-m-d H:i:s') . "\n"
        ], __METHOD__);
    }

    /**
     * @view update.php
     * @return mixed
     */
    public function actionRefresh() {
        Yii::error([
            'name' => 'TestController',
            'action' => 'actionRefresh',
            date('Y-m-d H:i:s') . "\n"
        ], __METHOD__);
    }

    /**
     * @view update.php
     * @return mixed
     */
    public function actionUpdate() {
        $count = 1000;
//        Console::startProgress(0, $count);
//        for ($n = 1; $n <= $count; $n++) {
//            usleep(1000);
//            Console::updateProgress($n, 1000);
//        }
//        Console::endProgress();

        Console::startProgress(0, $count, 'Counting objects: ', true);
//        Console::startProgress($i = 0, $count);
        for ($i = 0; $i < $count; $i++) {
            Console::output($i);
//            $hello = Console::ansiFormat("Hello", [Console::FG_YELLOW]);
//            $world = Console::ansiFormat("World", [Console::FG_GREEN]);
//            Console::output($hello . ' ' . $world);

            Console::updateProgress($i, $count);
        }

        Console::endProgress("update done." . PHP_EOL);
    }

}
